//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    page: 0,
    code:'',
    nav:[
      { pic: '/images/alltag.png',name:'全部兼职',id:0},
      { pic: '/images/dayend.png', name: '日结', id: 1 },
      { pic: '/images/nearby.png', name: '附近', id: 2 },
      { pic: '/images/hot.png', name: '热门', id: 3},   
    ],
    wap: false
    
  },
  // 关闭
  open: function () {
    var types = !this.data.wap
    this.setData({
      wap: types
    })
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  start_job:function(e){
    var id = e.currentTarget.dataset.id;
    wx.setStorage({
      key:'job',
      data:id
    })
    wx.switchTab({
      url: '../job/job',
    })
  },
  start_recommended:function(e){
    wx.navigateTo({
      url: '../recommendedil/recommendedil?jobdeil=' + e.currentTarget.dataset.id
    })
  },
  onLoad: function () {

    wx.request({
      //获取openid接口  
      url: 'https://www.135k.com/addons/sd_humans/tp/index.php/users/getvip',
      data: {
        uid: wx.getStorageSync('uid')
      },
      method: 'post',
      success: function (resid) {
        wx.setStorageSync('step', resid.data);
      }
    })
    let that = this;
    // 获取轮播图
    var uid=wx.getStorageSync('uid');
    if(uid!=''){
        that.setData({
          wap: false
        })
      }else{
        that.setData({
          wap: true
        })
      
    }

    // 获取用户基本信息
    wx.login({
      success: function (resss) {
        that.setData({
          code: resss.code
        })
      }
    })
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  sendRequest: function (e) {
    var that=this;
    var res = e.detail;
    //获取用户缓存token 此token是服务器作为用户唯一验证的标识，具体请看后端代码
    var utoken = wx.getStorageSync("utoken");
    wx.setStorageSync("nickname", res.userInfo.nickName)
    wx.request({
      //用户登陆URL地址，请根据自已项目修改
      url: app.data.Url + 'User/logins',
      method: "POST",
      data: {
        utoken: utoken,
        code: that.data.code,
        encryptedData: res.encryptedData,
        iv: res.iv,
        bid: 51
      },
      fail: function (res) {
        console.log(1212)
      },
      success: function (resa) {
        console.log(resa);
        var utoken = resa.data.utoken;
        console.log(resa)
        if (resa.data.success == 10) {
          console.log(resa.data.openid)
          wx.setStorageSync("openid", resa.data.openid);
          wx.request({
            //用户登陆URL地址，请根据自已项目修改
            url: app.data.Url + 'User/getUid',
            method: "POST",
            data: {
              openid: resa.data.openid
            },
            fail: function (res) {
              console.log(1111112222222)
            },
            success: function (res) {
              console.log(res.data.data)
              wx.setStorageSync("uid", res.data.data)
              // wx.setStorageSync("phone", res.data.phone)
              wx.setStorageSync("head", res.data.head)
              //    console.log(wx.getStorageSync("phone"))
              if (true) {
                that.setData({
                  wap: false
                })
              }
            }
          })
        }
        //设置用户缓存
        wx.setStorageSync("utoken", utoken);
      }
    })
  },
})
